<?php namespace Admin\Controller;
use Common\Model\Tag;

class TagController extends CommonController{
    private $model;

    public function __auto(){
        $this->model=new Tag();
    }
//    标签列表显示
    public function index(){
//        获得全部数据 select * from tag
        $tagData=$this->model->get();
//        p($tagData);
        View::with('tagData',$tagData);
        View::make();
    }

//    添加标签
    public function addtag(){
        if(IS_POST){
            if($this->model->store()){
                View::success('添加成功',U('index'));
            }else{
                View::error($this->model->getError());
            }
        }
        View::make();
    }

//    删除标签
    public function deltag(){
        $tid=Q('get.tid',0,'intval');
        $this->model->where("tid={$tid}")->delete();
        View::success('删除成功');
    }

//    编辑标签
    public function edittag(){
        if(IS_POST){
            if($this->model->edit()){
                View::success('编辑成功','index');
            }else{
                View::error($this->model->getError());
            }

        }

        $tid=Q('get.tid',0,'intval');
        $tagData=$this->model->where("tid={$tid}")->find();
//        p($tagData);
        View::with('tagData',$tagData);
        View::make();
    }
}